package com.huopaolan.lib_core.Base;

import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.huopaolan.lib_core.Mvp.Presenter.IPresenter;
import com.huopaolan.lib_core.Mvp.View.IView;

import javax.inject.Inject;

/**
 * Fragment封装
 */
public abstract class BaseFragment<P extends IPresenter> extends Fragment implements IFragment, IView {
    protected int page = 1;
    //dagger2注入
    @Inject
    protected P p;

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = createView(inflater);
        setUpDagger();
        initView(view);
        initData();
        return view;
    }

    @Override
    public void onDestroy() {
        if (p != null) {
            p.destroy();
        }
        p = null;
        super.onDestroy();
    }

    @Override
    public void showMessage(String message) {
        Toast.makeText(getContext(), message, Toast.LENGTH_SHORT).show();
    }
}
